SPMetal generate code: EntityList<Item> not EntityList<Currency> in data context class?

I create and deploy custom list by visual studio 2010. I have 3 file: Instance, element and schema. Then I used SPMetal to generate code.

[Microsoft.SharePoint.Linq.ListAttribute(Name="Currency")]
public Microsoft.SharePoint.Linq.EntityList<Item> Currency
{
 get {
 return this.GetList<Item>("Currency");
}
}

If I create custom list(Currency) by sharepoint, SPMetal will generate code below. What should I edit in my xml file(instance, element, schema) so that SPMetal gen to:

[Microsoft.SharePoint.Linq.ListAttribute(Name="Currency")]
public Microsoft.SharePoint.Linq.EntityList<Currency> Currency
{
 get {
 return this.GetList<Currency>("Currency");
}
}




January 4th, 2013 4:52am

You cannot do that. I guess you are getting the concept wrong. Item is The content type of the list items.

TEntity

The content type of the list items.

you will find Item to be replaced by Document or Announcement when you generate spmetal for announcements and document library list type which are nothing by content types associated to the list.

For more information 

http://msdn.microsoft.com/en-us/library/ee583001.aspx, check the type parameter section you will get clarified.

http://msdn.microsoft.com/en-us/library/ee554955.aspx

Free Windows Admin Tool Kit Click here and download it now
January 4th, 2013 5:40am

ProgrammerVN-

Did you ever get an answer to this?  I recently added a list built using Visual Studio 2012 and it's exhibiting the same behavior.

Regards - Pete

February 26th, 2013 9:22pm

Hi there,

The 'Item' you are mentioning is the ContentType for that list. Thats what it is.

SP Metal will generate List<some_object_you_want> only if you have a contentType created and enabled for that list. Otherwise, the content will Always be Item (which is the default contenttype for custom lists)

Try this:

  1. Create one ContentType using visual studio 2010 template (Add -> New Item -> ContentType).
  2. Add some fields (doesnt matter which ones)
  3. Create one List using visual studio 2010 template (Add -> New Item -> List) and use Customizable list.
  4. Double click the list generated and click 'ContentTypes'.
  5. Select the content type you just created.
  6. Deploy the solution and generate spmetal.

Lets say your ContentType is called 'Currency'.

SPMetal should generate as you want:

public Microsoft.SharePoint.Linq.EntityList<Currency> Currency
Free Windows Admin Tool Kit Click here and download it now
February 26th, 2013 10:18pm

Peter,

Same behavior applies to VS2012.

Please have a look on ContentTypes (which is what spmetal uses for the generics).

Bruno

February 26th, 2013 10:20pm

Hi,

Tested in VS 2012.
You should change Schema.xml.

Name="ListFieldsContentType"

to

 Name="$Resources:core,Item;"  Group="$Resources:core,List_Content_Types;" Description="$Resources:core,ItemCTDesc;" Version="1"

Remove sections:

ContentTypeRef

and finally add <Folder TargetName="Item"/> in ContentType section.

Before:

<ContentTypes>
      <ContentType ID="0x0100cd1d8f732d3947f0b1bada45cb76c152" Name="ListFieldsContentType">
        <FieldRefs>
          <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" />
          <FieldRef ID="{0a87b432-0638-4428-9df9-fd68ba6f8efb}" Name="Name" />
        </FieldRefs>
      </ContentType>
      <ContentTypeRef ID="0x01">
        <Folder TargetName="Item" />
      </ContentTypeRef>
      <ContentTypeRef ID="0x0120" />
    </ContentTypes>

After:

<ContentTypes>
      <ContentType ID="0x0100cd1d8f732d3947f0b1bada45cb76c152"  Name="$Resources:core,Item;"  Group="$Resources:core,List_Content_Types;" Description="$Resources:core,ItemCTDesc;" Version="1">
        <FieldRefs>
          <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" />
          <FieldRef ID="{0a87b432-0638-4428-9df9-fd68ba6f8efb}" Name="Name" />
        </FieldRefs>
        <Folder TargetName="Item"/>
      </ContentType>
    </ContentTypes>

Regards

Adam


  • Edited by Adam Banach Wednesday, March 05, 2014 3:41 PM
Free Windows Admin Tool Kit Click here and download it now
March 5th, 2014 3:41pm

did you find any solution to this?
August 20th, 2015 2:45pm

i faced the same problem as you did and after a couple of days on tinkering around i found the solution.

1.add the a list to your visual studio sharepoint project
2.add whatever columns you want
3.open the schema.xml file and lookup the content type property, it should be written along the line contentypeid="guid" name="listfieldcontenttype"
4.change the name element to something that makes sense, for example CurrencyContentType or ActualPurchaseOrderContentType
5.double click the list again and vs will open it in the designer view
6.at the bottom of the page, you will find "content type" botton, click it
7.you will find your contenttype and "item" and "folder" content types
8.delete those and leave only yours (right click- delete)
9.deploy
Free Windows Admin Tool Kit Click here and download it now
August 23rd, 2015 7:20am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics